﻿namespace EasyXaf.ObjectSpaces.OData;

public class ODataParseCriteriaScope : IDisposable
{
    private List<IDisposable> _additionalParseCriteriaScopes;

    public ODataParseCriteriaScope(ODataObjectSpace objectSpace)
    {
        _additionalParseCriteriaScopes = new List<IDisposable>();
        foreach (var additionalObjectSpace in objectSpace.AdditionalObjectSpaces)
        {
            _additionalParseCriteriaScopes.Add(additionalObjectSpace.CreateParseCriteriaScope());
        }
    }

    public void Dispose()
    {
        if (_additionalParseCriteriaScopes != null)
        {
            for (var num = _additionalParseCriteriaScopes.Count - 1; num >= 0; num--)
            {
                _additionalParseCriteriaScopes[num].Dispose();
            }
            _additionalParseCriteriaScopes.Clear();
            _additionalParseCriteriaScopes = null;
        }

        GC.SuppressFinalize(this);
    }
}
